import {AxiosInstance} from 'axios';
import axios from 'axios'

const instance: AxiosInstance = axios.create({
  baseURL: 'http://localhost:8081/goodstype',
  timeout: 2000,
  headers: {
    'Content-type': 'application/json'
  },

  withCredentials: true
})


async function findAllTypes() {
  let response = await instance.get('/')
  return response.data
}

async function insertOneType(goodsType: GoodsType) {
  let response = await instance.post('/', JSON.stringify(goodsType))
  return response.data
}

async function deleteOneType(id: number) {
  let response = await instance.delete('/', {
    params: {
      id
    }
  })
  return response.data
}

async function updateOneType(goodsType: GoodsType) {
  let response = await instance.put('/', JSON.stringify(goodsType))
  return response.data
}


export {
  findAllTypes,
  insertOneType,
  deleteOneType,
  updateOneType
}